package com.sam.im.heiqun.uis.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sam.im.heiqun.R;
import com.sam.im.heiqun.entities.PhpStatusEntivity;
import com.sam.im.heiqun.entities.UserEntivity;
import com.sam.im.heiqun.nets.PGService;
import com.sam.im.heiqun.uis.activities.AboutUsActivity;
import com.sam.im.heiqun.uis.activities.AutoCheckActvity;
import com.sam.im.heiqun.uis.activities.CollectionActivity;
import com.sam.im.heiqun.uis.activities.LiangSelecterSortActivity;
import com.sam.im.heiqun.uis.activities.MyWalletActivity;
import com.sam.im.heiqun.uis.activities.MycircleActivty;
import com.sam.im.heiqun.uis.activities.NewPasswordActivity;
import com.sam.im.heiqun.uis.activities.PersonalInformationActivity;
import com.sam.im.heiqun.uis.activities.PrivacyActivity;
import com.sam.im.heiqun.uis.activities.QRcode;
import com.sam.im.heiqun.uis.activities.SetTwoActivity;
import com.sam.im.heiqun.utils.ToastUtil;
import com.sam.im.heiqun.utils.ToolsUtils;
import com.yuyh.library.nets.callbacks.AbsAPICallback;
import com.yuyh.library.nets.exceptions.ApiException;
import com.yuyh.library.uis.fragments.BaseFragment;
import com.yuyh.library.utils.GlideUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class SetTwoFragment extends BaseFragment {

    @BindView(R.id.nick)
    TextView nick;
    @BindView(R.id.user_id)
    TextView userIdText;
    @BindView(R.id.txt_buy_im)
    TextView txt_buy_im;

    @BindView(R.id.head_image)
    ImageView headImage;
    @BindView(R.id.two_dimension_code)
    ImageView twoDimensionCode;

    @BindView(R.id.my_wallet)
    LinearLayout myWallet;
    @BindView(R.id.colaction_layout)
    LinearLayout colaction;
    @BindView(R.id.privacy)
    LinearLayout privacy;

    @BindView(R.id.linear_nick)
    LinearLayout linearNick;


    String headImgStr;

    @Override
    public int getContentViewId() {
        return R.layout.fragment_set_two;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        initData();
    }

    @Override
    public void onResume() {
        super.onResume();
        initData();
    }

    private void initData() {
        UserEntivity user = ToolsUtils.getUser();
        if (null==user)return;
        headImgStr = user.getHeadUrl();
        if (headImage != null) {
            GlideUtils.loadHeadCircularImage(getActivity(), headImgStr, headImage);
        }
        String name = ToolsUtils.getNick(user);
        String imid = user.getIMNo() ;
        userIdText.setText("ID："+user.getId());
        userIdText.setVisibility(View.VISIBLE);
        if (null!=imid && imid.length()>0){
//            userIdText.setText("IM：" + user.getIMNo());
//            txt_buy_im.setVisibility(View.GONE);
//            userIdText.setVisibility(View.VISIBLE);
        }else {
//            txt_buy_im.setVisibility(View.VISIBLE);
//            userIdText.setVisibility(View.GONE);
        }


//        if (user.getIsAuth()!=0){
            //没有认证
//            tvisauth.setVisibility(View.VISIBLE);
//        }
        nick.setText(name);
    }

    /**
     * 点击事件处理
     */
    @OnClick({R.id.head_image, R.id.two_dimension_code, R.id.privacy,
            R.id.colaction_layout,R.id.nick, R.id.my_wallet,  R.id.linear_nick,R.id.circle_layout,
            R.id.txt_buy_im})
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.head_image:   // 个人信息
            case R.id.linear_nick:
            case R.id.nick:
                startActivity(PersonalInformationActivity.class);
                break;

            case R.id.two_dimension_code:// 二维码
                Intent intentQR = new Intent(getContext(), QRcode.class);
                if (headImgStr != null) {
                    intentQR.putExtra("img", headImgStr);
                }
                startActivity(intentQR);
                break;

            case R.id.privacy:    // 系统设置
                startActivity(SetTwoActivity.class);

                break;

 //           case R.id.version: // 版本更新
   //             MainActivity.mainActivity.getVersion(true);
//                showToast("当前已经是最新版本");
//                ToastUtil.showtoast(getContext(),"当前已经是最新版本");
//                break;

//            case R.id.about_our:    // 关于我们
//                startActivity(AboutUsActivity.class);
//                break;

            case R.id.my_wallet: // 我的钱包
                startActivity(MyWalletActivity.class);
                break;

//            case R.id.real_name_approve:    // 实名认证
//                //startActivity(AutoCheckActvity.class);
//                if (ToolsUtils.getUser().getIsAuth()==0){
//                    startActivity(AutoCheckActvity.class);
//                }
//               // authcheck();//认证状态错误
//                break;
            case R.id.circle_layout://相册
                startActivity(MycircleActivty.class);
                break;
            case R.id.colaction_layout://收藏
                startActivity(CollectionActivity.class);
                break;
            case R.id.txt_buy_im://
                Intent intent = new Intent(getActivity(), LiangSelecterSortActivity.class);
                intent.putExtra("type", 1);
                startActivity(intent);
                break;
        }
    }

}
